/*
 * 学科
 */

import { createAPI } from '@/utils/request'
import moment from 'moment'

// 学科列表
export const list = params => createAPI('/subjects', 'get', params).then(res => {
  const data = {
    ...res.data,
    items: res.data.items.map((row, idx) => {
      return {
        ...row,
        index: (params.page - 1) * params.pagesize + idx + 1,
        addDate: moment(row.addDate).format('YYYY-MM-DD'),
        isFrontDisplay: row.isFrontDisplay === 1 ? '是' : '否'
      }
    })
  }
  return data
})
// 学科简单列表
export const simple = data => createAPI('/subjects/simple', 'get', data)

// 学科详情
export const detail = data => createAPI(`/subjects/${data.id}`, 'get', data)

// 学科添加
export const add = data => createAPI('/subjects', 'post', data)

// 学科修改
export const update = data => createAPI(`/subjects/${data.id}`, 'put', data)

// 学科删除
export const remove = data => createAPI(`/subjects/${data.id}`, 'delete', data)
